<template>
  <div id="app">
    <div class="container">
      <draw
        ref="drawDOM"
        @init="handleInit"
        smooth
        background="#ff9999"
        color="#333"
      ></draw>
    </div>
    <button @click="clear">清空</button>
    <button @click="ok">确认</button>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      canvas: null,
    }
  },
  methods: {
    handleInit(canvas) {
      this.canvas = canvas
    },
    clear() {
      this.$refs.drawDOM.clean()
    },
    ok() {
      let res = this.$refs.drawDOM.getImage()
      // let res = this.canvas?.toDataURL()
      let img = new Image()
      img.src = res
      let newWin = window.open('', '_blank')
      newWin.document.write(img.outerHTML)
      newWin.document.title = '示例返图'
      newWin.document.close()
    },
  },
}
</script>

<style lang="scss">
* {
  box-sizing: border-box;
}
body,
html,
#app {
  height: 100%;
  margin: 0;
  padding: 0;
}
#app {
  /*position: fixed;*/
  /*top: 0;*/
  /*left: 0;*/
  /*right: 0;*/
  /*bottom: 0;*/
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
.block {
  height: 100px;
  border: 1px solid #666;
}
.container {
  width: 100vw;
  height: 80vh;
  border: 1px solid #333;
  margin: 0 auto;
}
</style>
